/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.AA中等题.power;

public class Main {
    public double myPow(double x, int n) {
        double res = 1;

        long i = n;
        if (i < 0) {
            x = 1 / x;
            i = -i;
        }
        double x1 = x * x;
        while (i > 1) {
            res *= x1;
            i -= 2;
        }
        if (i == 1)
            res *= x;
        return res;

    }

}
